//userCenter.html所用代碼  start
function userCenterInit() {
    var a = {
        name: "",
        iphone: "",
        cardId: 0000000,
        Msum: 0
    };
    var data = null;
    $.ajax({

        type: "GET",

        url: "ajax/userCenter.php",

        data: {
            username: $("#username").val(),
            content: $("#content").val()
        },

        dataType: "json",

        success: function(data) {
            var data = JSON.parse(data);
            a.name = data['name'];
            a.iphone = data['iphone'];
            a.cardId = data['cardId'];
            a.Msum = data['Msum'];
            console.log(data['Msum']);
            $(".getCardNo").text(data['cardId']);
            $("#getNum").text(data['Msum']);
        },
        error: function(e) {
            console.log(e);
        }

    });

}

//userCenter.html所用代碼  end
//coupons.html所用代碼     start
function couponsInit() {
    var couponList = [];
    var data = null;
    $.ajax({

        type: "GET",

        url: "ajax/coupons.php",

        data: {
            username: $("#username").val(),
            content: $("#content").val()
        },

        dataType: "json",

        success: function(data) {
            var data = JSON.parse(data);
            var html = '';
            $(".getCardNo").text(data['cardId']);
            $("#getNum").text(data['Msum']);
            $("#couponsList").empty();

            $.each(data, function(commentIndex, comment) {
                console.log(data);
                var obj = {
                    couponId: '',
                    getDate: '',
                    barCardUrl: '',
                    isRedeemed: true
                }
                var iconHtml = '';
                obj.couponId = comment['couponId'];
                obj.barCardUrl = comment['barCardUrl'];
                obj.getDate = comment['getDate']
                obj.isRedeemed = comment['isRedeemed'];
                couponList.push(obj);

                if (comment.isRedeemed == true) {
                    html += '<li class="redeemedLi">'
                    iconHtml = '<img src="img/cou_redeemed.png" class="weui_media_appmsg_thumb leftImg" alt="">'
                    status = '已使用'
                } else {
                    html += '<li>'
                    iconHtml = '<img src="img/coupons.png" class="weui_media_appmsg_thumb leftImg" alt="">'
                    status = '未使用'
                }

                html += '<div class="weui-flex js-category">' +
                    '<div class="weui-flex-item">' +
                    '<div class="weui_panel">' +
                    '<div class="weui_panel_bd">' +
                    ' <a href="javascript:void(0);" class="weui_media_box weui_media_appmsg">' +
                    '<div class="weui_media_hd">' +
                    iconHtml +
                    '</div>' +
                    '<div class="weui_media_bd">' +
                    '<h4 class="weui_media_title couponTitle">10元</h4>' +
                    '<p class="weui_media_desc couponKind">现金券</p>' +
                    '<p class="weui_media_desc couponUsage"> 满50抵用10元现金券</p>' +
                    '</div>' +
                    '</a>' +
                    '</div>' +
                    '</div>' +
                    '</div>' +
                    '<i class="icon icon-74"></i>' +
                    '</div>' +
                    '<div class="page-category js-categoryInner">' +


                    '<div class="weui_cells">' +
                    ' <div class="weui_cell barCard">' +
                    '<img src="' + comment['barCardUrl'] + '" alt="条形码">' +
                    '</div>' +
                    '<div class="weui_cell">' +
                    '<div class="weui_cell_bd weui_cell_primary">' +
                    '<p>优惠券号</p>' +
                    '</div>' +
                    '<div class="weui_cell_ft waringColor">' +
                    comment['couponId'] +
                    '</div>' +
                    '</div>' +
                    '<div class="weui_cell">' +
                    '<div class="weui_cell_bd weui_cell_primary">' +
                    '<p>获得日期</p>' +
                    '</div>' +
                    '<div class="weui_cell_ft waringColor">' +
                    comment['getDate'] +
                    '</div>' +
                    '</div>' +
                    '<div class="weui_cell">' +
                    '<div class="weui_cell_bd weui_cell_primary">' +
                    '<p>使用说明</p>' +
                    '</div>' +
                    '<div class="weui_cell_ft waringColor">一经使用,概不退换</div>' +
                    '</div>' +
                    '<div class="weui_cell">' +
                    '<div class="weui_cell_bd weui_cell_primary">' +
                    '<p>使用状态</p>' +
                    '</div>' +
                    '<div class="weui_cell_ft waringColor">' +
                    status +
                    '</div>' +
                    '</div>' +
                    '</div>' +
                    '</div>' +
                    '</li>'


            });
            $('#couponsList').html(html);
        },
        error: function(e) {
            console.log(e);
        }

    });

}
//coupons.html所用代碼     end
//userMsg.html所用代码   start
var a = {
    nickName: null,
    sex: null,
    iphone: null,
    birthday: null,
    email: null,
    profession: null,
    addressA: null,
    addressB: null,
    s: 0
};

function userMsgInit() {

    var data = null;
    $.ajax({
        type: "GET",
        url: "ajax/userMsg.php",
        data: {
            username: $("#username").val(),
            content: $("#content").val()
        },
        dataType: "json",
        success: function(data) {
            var data = JSON.parse(data);
            a.nickName = data['nickName'] || a.nickName;
            a.sex = data['sex'] || a.sex;
            a.iphone = data['iphone'] || a.iphone;
            a.birthday = data['birthday'] || a.birthday;
            a.email = data['email'] || a.email;
            a.profession = data['profession'] || a.profession;
            a.addressA = data['addressA'] || a.addressA;
            a.addressB = data['addressB'] || a.addressB;
            if (a.nickName != null) {
                $("#nickName").attr("value", a.nickName);
                $("#nickName").addClass("inputed");
                a.s++;
            }
            if (a.sex != null) {
                $("#gender").attr("value", a.sex);
                $("#gender").addClass("inputed");
                a.s++;
            }
            if (a.iphone != null) {
                $("#iphone").attr("value", a.iphone);
                $("#iphone").addClass("inputed");
                a.s++;
            }
            if (a.birthday != null) {
                a.birthday = a.birthday.replace(/\//g, '-')
                console.log(a.birthday);
                $("#birthday").attr("value", a.birthday);
                $("#birthday").addClass("inputed");
                a.s++;
            }
            if (a.email != null) {
                $("#email").attr("value", a.email);
                $("#email").addClass("inputed");
                a.s++;

            }
            if (a.profession != null) {
                $("#profession").attr("value", a.profession);
                $("#profession").addClass("inputed");
                a.s++;
            }
            if (a.addressA != null) {
                $("#ssx").attr("value", a.addressA);
                $("#ssx").addClass("inputed");
                a.s++;
            }
            if (a.addressB != null) {
                $("#addressB").attr("value", a.addressB);
                $("#addressB").addClass("inputed");
                a.s++;
            }
            console.log(a.s);
            if (a.s >= 8) {

                $("#save").css("display", "none");
                //$("input").addClass("inputed");
            }

        },
        error: function(e) {
            console.log(e);
        }

    });

}

function sendMsg() { //未完成
    var data = null;
    //
    $.ajax({
        type: "POST",
        url: "ajax/postuserMsg.php",
        data: {
            username: $("#username").val(),
            content: $("#content").val()
        },
        dataType: "json",
        success: function(data) {
            // var data = JSON.parse(data);
            // a.nickName = data['nickName'] || a.nickName;
            // a.sex = data['sex'] || a.sex;
            // a.iphone = data['iphone'] || a.iphone;
            // a.birthday = data['birthday'] || a.birthday;
            // a.email = data['email'] || a.email;
            // a.profession = data['profession'] || a.profession;
            // a.addressA = data['addressA'] || a.addressA;
            // a.addressB = data['addressB'] || a.addressB;
            // if (a.nickName != null) {
            //     $("#nickName").attr("value", a.nickName);
            //     $("#nickName").addClass("inputed");
            //     a.s++;
            // }
            // if (a.sex != null) {
            //     $("#gender").attr("value", a.sex);
            //     $("#gender").addClass("inputed");
            //     a.s++;
            // }
            // if (a.iphone != null) {
            //     $("#iphone").attr("value", a.iphone);
            //     $("#iphone").addClass("inputed");
            //     a.s++;
            // }
            // if (a.birthday != null) {
            //     a.birthday = a.birthday.replace(/\//g, '-')
            //     console.log(a.birthday);
            //     $("#birthday").attr("value", a.birthday);
            //     $("#birthday").addClass("inputed");
            //     a.s++;
            // }
            // if (a.email != null) {
            //     $("#email").attr("value", a.email);
            //     $("#email").addClass("inputed");
            //     a.s++;

            // }
            // if (a.profession != null) {
            //     $("#profession").attr("value", a.profession);
            //     $("#profession").addClass("inputed");
            //     a.s++;
            // }
            // if (a.addressA != null) {
            //     $("#ssx").attr("value", a.addressA);
            //     $("#ssx").addClass("inputed");
            //     a.s++;
            // }
            // if (a.addressB != null) {
            //     $("#addressB").attr("value", a.addressB);
            //     $("#addressB").addClass("inputed");
            //     a.s++;
            // }
            // console.log(a.s);
            // if (a.s >= 8) {

            //     $("#save").css("display", "none");
            //     //$("input").addClass("inputed");
            // }

        },
        error: function(e) {
            console.log(e);
        }

    });

}
//userMsg.html所用代码   end